import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

import Notfound from '@/components/page/notfound'
import Login from "@/components/login/signup"
import Firstpage from "@/components/show/Firstpage"

// const originalPush = Router.prototype.push
//修改原型对象中的push方法
// Router.prototype.push = function push(location) {
//    return originalPush.call(this, location).catch(err => err)
// }

const  routes=[
    {
      path: '/',
      redirect:"/login"
    },
    // {
    //   path: '/',
    //   redirect:"/firstpage"
    // },
    {
      path:"/login",
      component:Login
    },
    {
      path:"/article/:id",
      component:()=>import('../components/show/Content')
    },
    {
      path:"/firstpage",
      name:"Firstpage",
      component:Firstpage,
      children:[
        {
          path:'/cate/:id',
          component:()=>import('../components/show/Catearticle')
        },
        {
          path:'/about',
          component:()=>import('../components/show/about') 
        },
        {
          path:"/index",
          component:()=>import('../components/show/Catearticle')
        },
        {
          path:"",
          redirect:"/index"
        }
      ]
      
    },
    
    
    {
      path:"/first",
      component:()=>import('../components/common/Header'),
      meta: { title: '文件' },
      children:[
        {
          path:"/dashboard",
          name:"Dashboard",
          meta: { title: '系统首页' },
          component:()=>import('../components/page/dashboard')
        },
        {
          path:"/cate",
          name:"Cate",
          meta: { title: '分类管理' },
          component:()=>import('../components/page/cate/cate')
        },
        {
          path:"/article",
          name:"Article",
          meta: { title: '文章管理' },
          component:()=>import('../components/page/article')
        },
        {
          path:"/info",
          name:"Info",
          meta: { title: '博客信息管理' },
          component:()=>import('../components/page/info')
        },
        {
          path:"/admin",
          name:"Admin",
          meta: { title: '管理员管理' },
          component:()=>import('../components/page/admin')
        }
       
      ]
    },
    
    {
      path:"/notfound",
      name:"Notfound",
      component:Notfound
    },
    {
      path:"/cateart",
      name:"Cateart",
      component:()=>import('../components/show/Catearticle')
      
    }
    
  ]
//创建路由器
  const router = new Router({
    // mode: 'history',
    routes
    
  })

 
  // router.beforeEach((to,form,next)=>{ 
  //   if(to.path==='/login'){
  //     next()
  //   }else{   
  //     if(!localStorage.getItem('token')){
  //       next("/login")
  //     }else{
  //       next()
  //     }
  //   }
  // })

  export default router

